'use strict';
const db = uniCloud.database();
exports.main = async (event, context) => {


	
	if (event.queryStringParameters) {
		event = {
			...event,
			...event.queryStringParameters
		}
	}
	
	var openId = event.openId
	var passowrd = event.passowrd 

	let result = await db.collection('wx_user').where({
		openid:openId
	}).get();

	if (result.data.length > 0) {
		let user = result.data[0]
		if(user.password !== passowrd || user.openid !== openId){
			return {
				success: false,
				msg: '用户不存在或账号密码错误'
			}
		}
		// delete user.password
		delete user.record
		return {
			success: true,
			data: user
		}
	} else {
		return {
			success: false,
			msg: '用户不存在或账号密码错误'
		}
	}
	
};
